<!DOCTYPE html>
<html>
  <head>
    <title>在浏览器打开</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="color-scheme" content="light dark" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover"
    />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <style type="text/css">
      * {
        margin: 0;
        padding: 0;
      }
      #topyd {
        width: 100%;
        margin: 0 auto;
        position: fixed;
        top: 0;
      }
      #topyd img {
        max-width: 100%;
      }

      #centeryd {
        width: 320px;
        margin: 180px auto 0;
      }

      #centeryd img {
        max-width: 320px;
      }

      #bottomyd {
        width: 320px;
        margin: 300px auto 0;
      }

      #bottomyd p {
        text-align: center;
        font-size: 18px;
        color: #ed2517;
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <!-- 顶部引导 -->
    <div id="topyd"></div>

    <div
      id="pdf"
      style="
        display: none;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      "
    >
      <svg
        style="width: 20%"
        t="1744091813157"
        class="icon"
        viewBox="0 0 1024 1024"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        p-id="2053"
        width="200"
        height="200"
      >
        <path
          d="M905.185809 178.844158C898.576738 172.685485 891.19337 165.824412 883.21687 158.436127 860.422682 137.322863 837.434925 116.207791 815.697647 96.487895 813.243072 94.261877 813.243072 94.261877 810.786411 92.037081 781.783552 65.781062 757.590948 44.376502 739.713617 29.293612 729.254178 20.469111 721.020606 13.860686 714.970549 9.501727 710.955023 6.608611 707.690543 4.524745 704.47155 2.998714 700.417679 1.07689 696.638044-0.094029 691.307277 0.005928 677.045677 0.273349 665.6 11.769337 665.6 26.182727L665.6 77.352844 665.6 128.522961 665.6 230.863194 665.6 256.448252 691.2 256.448252 896 256.448252 870.4 230.863194 870.4 998.414942 896 972.829884 230.381436 972.829884C187.90385 972.829884 153.6 938.623723 153.6 896.20663L153.6 26.182727 128 51.767786 588.8 51.767786C602.93849 51.767786 614.4 40.312965 614.4 26.182727 614.4 12.05249 602.93849 0.597669 588.8 0.597669L128 0.597669 102.4 0.597669 102.4 26.182727 102.4 896.20663C102.4 966.91021 159.652833 1024 230.381436 1024L896 1024 921.6 1024 921.6 998.414942 921.6 230.863194 921.6 205.278135 896 205.278135 691.2 205.278135 716.8 230.863194 716.8 128.522961 716.8 77.352844 716.8 26.182727C716.8 39.813762 705.748075 50.91427 692.267725 51.167041 687.705707 51.252584 685.069822 50.435995 682.52845 49.231204 682.259458 49.103682 683.344977 49.796618 685.029451 51.010252 689.779394 54.432502 697.145822 60.34494 706.686383 68.394196 724.009052 83.009121 747.816448 104.072869 776.413589 129.961594 778.850014 132.168064 778.850014 132.168064 781.285216 134.376514 802.876774 153.964212 825.739479 174.96442 848.413564 195.966437 856.350957 203.3185 863.697005 210.144893 870.269888 216.269843 874.209847 219.941299 877.019309 222.565641 878.499674 223.951409 888.81866 233.610931 905.019017 233.081212 914.684179 222.768247 924.349344 212.455283 923.819315 196.264383 913.500326 186.604861 911.981323 185.182945 909.155025 182.542876 905.185809 178.844158ZM102.4 461.128719 0 461.128719 0 896.074709 512 896.074709 1024 896.074709 1024 461.128719 153.6 461.128719 153.6 460.531049 102.4 460.531049 102.4 461.128719ZM208.2 711 208.2 819.2 157.6 819.2 157.6 528 269 528C301.533495 528 327.366571 536.466581 346.5 553.4 365.633429 570.333419 375.2 592.733195 375.2 620.6 375.2 649.133476 365.833427 671.333254 347.1 687.2 328.366573 703.066746 302.133502 711 268.4 711L208.2 711ZM208.2 670.4 269 670.4C287.00009 670.4 300.733286 666.166709 310.2 657.7 319.666714 649.233291 324.4 637.000079 324.4 621 324.4 605.266588 319.600047 592.700047 310 583.3 300.399951 573.899953 287.200083 569.066669 270.4 568.8L208.2 568.8 208.2 670.4ZM419.4 819.2 419.4 528 505.4 528C531.133461 528 553.966566 533.733276 573.9 545.2 593.833434 556.666724 609.266611 572.933229 620.2 594 631.133389 615.066771 636.6 639.199863 636.6 666.4L636.6 681C636.6 708.600139 631.100055 732.866562 620.1 753.8 609.099945 774.733438 593.433436 790.866609 573.1 802.2 552.766564 813.533391 529.466799 819.2 503.2 819.2L419.4 819.2ZM470 568.8 470 778.8 503 778.8C529.533466 778.8 549.89993 770.500083 564.1 753.9 578.30007 737.299917 585.533331 713.466822 585.8 682.4L585.8 666.2C585.8 634.599842 578.933402 610.46675 565.2 593.8 551.466598 577.13325 531.533463 568.8 505.4 568.8L470 568.8ZM854.8 695.8 737.6 695.8 737.6 819.2 687 819.2 687 528 872 528 872 568.8 737.6 568.8 737.6 655.4 854.8 655.4 854.8 695.8Z"
          fill="#5E5E5E"
          p-id="2054"
        ></path>
      </svg>
      <a href="" download="">卷宗卷皮.pdf</a>
    </div>

    <!-- 底部引导 -->
    <div id="bottomyd">
      <p>本站不支持在微信打开</p>
      <p>请在浏览器打开访问</p>
    </div>
  </body>

  <!-- 判断浏览器 -->
  <script>
    if (!iSWX()) {
      const { type, link, typeName, id } = getParams();
      console.log(type, link);
      if (type == "pdf") {
        // axiosDown(link);
        $("#pdf").css({
          display: "flex",
        });
        downloadFile(typeName, id);
      } else {
        creatImg(link);
      }
    }

    function creatImg(link) {
      const linkArr = link.split(";");
      linkArr.forEach((item, index) => {
        const urlArr = item.split("/");
        const name = urlArr.pop();
        // 创建 <a> 元素用于下载
        const a = document.createElement("a");
        // 设置 <a> 元素的 href 属性为图片的源地址
        a.href = item;
        // 设置 <a> 元素的 download 属性为图片的下载名
        a.download = name;

        // 创建 <img> 元素用于显示图片
        const img = document.createElement("img");
        // 设置 <img> 元素的 src 属性为图片的源地址
        img.src = item;
        // 设置 <img> 元素的 alt 属性
        img.alt = name;
        // 将 <img> 元素添加到 <a> 元素内部
        a.appendChild(img);
        document.body.appendChild(a);
      });
    }

    function iSWX() {
      var ua = navigator.userAgent.toLowerCase();
      var isWeixin = ua.indexOf("micromessenger") != -1;
      var isAndroid = ua.indexOf("android") != -1;
      var isIos = ua.indexOf("iphone") != -1 || ua.indexOf("ipad") != -1;

      // 判断是不是在微信客户端打开
      if (isWeixin) {
        return true;
        // 判断是在Android的微信客户端还是Ios的微信客户端
        if (isAndroid) {
          // 是在Android的微信客户端
          $("#topyd").html("<img src='./ios.jpeg'/>");
        } else if (isIos) {
          // 是在Ios的微信客户端
          $("#topyd").html("<img src='./ios.jpeg'/>");
        } else {
          // 未知设备系统，默认使用安卓的引导方式
          $("#topyd").html("<img src='./ios.jpeg'/>");
        }
      } else {
        return false;
        // window.location.href = link;
        // downloadFile(data, filename, type)
        //   downloadFile(blob, new Date().getTime(), "xlsx");
        // axiosDown(link.split("blob:")[1])
      }
    }

    function downloadFile(typeName, id) {
      var settings = {
        url: `http://47.92.235.205/jy/jyPDF/down?id=${id}&typeName=${typeName}`,
        method: "GET",
        xhrFields: {
          // 设置响应类型为二进制数据
          responseType: "blob",
        },
      };

      $.ajax(settings).done((response) => {
        console.log(response);
        // 创建一个临时的 URL 对象
        const url = window.URL.createObjectURL(response);
        // 创建一个 <a> 元素
        const a = document.createElement("a");
        a.href = url;
        // 设置下载的文件名
        a.download = "downloaded-file.pdf";
        // 模拟点击 <a> 元素触发下载
        a.click();
        // 释放临时的 URL 对象
        window.URL.revokeObjectURL(url);
      });
    }

    function axiosDown(url) {
      axios({
        method: "get",
        url: url,
        params: { name: "Jack" },
        responseType: "blob", // 设置响应类型为 blob
        // headers: {
        // 'Content-Type': 'application/json',
        // 'Authorization': 'Bearer ' + sessionStorage.getItem('access_token')
        // }
      })
        .then(function (res) {
          // 创建 Blob 对象
          let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
          // 创建临时 URL
          let url = window.URL.createObjectURL(blob);
          // 创建 a 标签用于下载
          let a = document.createElement("a");
          a.href = url;
          a.download = "表格.xlsx";
          a.click();
          // 释放 URL 对象
          window.URL.revokeObjectURL(url);
        })
        .catch(function (error) {
          console.log("error", error);
        });
    }

    function getParams() {
      // 获取当前页面的URL
      const urlParams = new URLSearchParams(window.location.search);

      // 获取type和link的值
      const type = urlParams.get("type");
      const link = urlParams.get("link");

      return {
        link,
        type,
      };
    }
  </script>
</html>
